﻿<UserControl x:Class="uTorrentNetClient.ModelDesign.Main.View.MainView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
             xmlns:local="clr-namespace:uTorrentNetClient.ModelDesign.Converter"
             mc:Ignorable="d">
    <UserControl.Resources>
        <local:TimeSpanDisplayConverter x:Key="TimeSpanConvert" />
        <local:QueuePriorityDisplayConverter x:Key="QueuePriorityConvert" />
        <local:SizeBytesDisplayConverter x:Key="SizeConverter" />
        <local:SizeBytesShowZeroDisplayConverter x:Key="SizeShowZeroConverter" />
        <local:SpeedBytesDisplayConverter x:Key="SpeedConverter" />
        <local:SeedPeerRatioDisplayConverter x:Key="SeedPeerRatioConverter" />
        <local:StatusDisplayConverter x:Key="StatusConverter" />
        <local:StatusImageDisplayConverter x:Key="StatusImageConverter" />
        <local:GroupImageDisplayConverter x:Key="GroupImageConverter" />
        <local:FilePriorityDisplayConverter x:Key="FilePriorityConverter" />
        <local:BoolDisplayConverter x:Key="BoolConverter" />
        <local:OptionValueDisplayConverter x:Key="OptionValueConverter" />

        <Style x:Key="{x:Type ProgressBar}" TargetType="{x:Type ProgressBar}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ProgressBar}">
                        <Grid MinHeight="14" MinWidth="50">
                            <Border Name="PART_Track" CornerRadius="0" Background="#00FFFFFF" BorderBrush="#FFF0F0F0" BorderThickness="1" />
                            <Border Name="PART_Indicator" CornerRadius="0" Background="#FFA0A0FF" BorderBrush="#00FFFFFF" BorderThickness="0" HorizontalAlignment="Left" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style TargetType="{x:Type TextBlock}" x:Key="ConnectedStyle">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=Connected}" Value="true">
                    <Setter Property="Foreground" Value="Green"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=Connected}" Value="false">
                    <Setter Property="Foreground" Value="DarkRed"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="120"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="36"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="20"/>
        </Grid.RowDefinitions>

        <ListBox ItemsSource="{Binding Path=Groups}" SelectedItem="{Binding Path=SelectedGroup}" Grid.Row="1" Grid.RowSpan="2" Grid.Column="0">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel CanHorizontallyScroll="False" CanVerticallyScroll="False" FlowDirection="LeftToRight" HorizontalAlignment="Left" VerticalAlignment="Center" Orientation="Horizontal">
                        <Image Height="16" Width="16" Source="{Binding Mode=OneWay, Path=GroupType, Converter={StaticResource GroupImageConverter}}" />
                        <TextBlock Text="{Binding Mode=OneWay, Path=Name}" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <ToolBarTray Grid.Row="0" Grid.ColumnSpan="2" VerticalAlignment="Top" OverridesDefaultStyle="False">
            <ToolBar Band="1" BandIndex="1" Grid.IsSharedSizeScope="False" Visibility="Visible">
                <Button ToolTip="Aktualisieren" Command="{Binding Path=RefreshCommand}">
                    <Image Height="24" Width="24" Source="/uTorrentNetClient.ModelDesign;component/Images/ToolBar5Refresh.png" />
                </Button>
                <Button ToolTip="Einstellungen" Command="{Binding Path=SettingsCommand}">
                    <Image Height="24" Width="24" Source="/uTorrentNetClient.ModelDesign;component/Images/ToolBar8Settings.png" />
                </Button>
            </ToolBar>
            <ToolBar Band="1" BandIndex="2">
                <Button ToolTip="Datei Öffnen" Command="{Binding Path=OpenTorrentFileCommand}">
                    <Image Height="24" Width="24" Source="/uTorrentNetClient.ModelDesign;component/Images/ToolBar1AddFile.png" />
                </Button>
            </ToolBar>
            <ToolBar Band="1" BandIndex="3">
                <Button ToolTip="Start" Command="{Binding Path=StartCommand}">
                    <Image Height="24" Width="24" Source="/uTorrentNetClient.ModelDesign;component/Images/ToolBar4Play.png" />
                </Button>
                <Button ToolTip="Pause" Command="{Binding Path=PauseCommand}">
                    <Image Height="24" Width="24" Source="/uTorrentNetClient.ModelDesign;component/Images/ToolBar5Pause.png" />
                </Button>
                <Button ToolTip="Stop" Command="{Binding Path=StopCommand}">
                    <Image Height="24" Width="24" Source="/uTorrentNetClient.ModelDesign;component/Images/ToolBar6Stop.png" />
                </Button>
                <Button ToolTip="Löschen" Command="{Binding Path=RemoveCommand}">
                    <Image Height="24" Width="24" Source="/uTorrentNetClient.ModelDesign;component/Images/ToolBar3Remove.png" />
                </Button>
            </ToolBar>
        </ToolBarTray>

        <dg:DataGrid Grid.Row="1" Grid.Column="1" AutoGenerateColumns="False" ItemsSource="{Binding Mode=OneWay, Path=Torrents}" BorderThickness="0" GridLinesVisibility="None" SelectedItem="{Binding Path=SelectedTorrent}" AlternatingRowBackground="Beige"
                     RowDetailsVisibilityMode="Collapsed" FontSize="11.5" HorizontalGridLinesBrush="Transparent" VerticalGridLinesBrush="Transparent" VerticalContentAlignment="Center">
            <dg:DataGrid.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Aktualisieren" Command="{Binding Path=RefreshCommand}"/>
                    <MenuItem Header="Start" Command="{Binding Path=StartCommand}"/>
                    <MenuItem Header="Pause" Command="{Binding Path=PauseCommand}"/>
                    <MenuItem Header="Stop" Command="{Binding Path=StopCommand}"/>
                    <MenuItem Header="Löschen" Command="{Binding Path=RemoveCommand}"/>
                    <MenuItem Header="Eigenschaften" Command="{Binding Path=PropertiesCommand}"/>
                </ContextMenu>
            </dg:DataGrid.ContextMenu>
            <dg:DataGrid.Columns>
                <dg:DataGridTemplateColumn Header="Name" SortMemberPath="Name" IsReadOnly="True" >
                    <dg:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel CanHorizontallyScroll="False" CanVerticallyScroll="False" FlowDirection="LeftToRight" HorizontalAlignment="Left" VerticalAlignment="Center" Orientation="Horizontal">
                                <Image Height="16" Width="16" Source="{Binding Mode=OneWay, Path=SimpleStatus, Converter={StaticResource StatusImageConverter}}" />
                                <TextBlock Text="{Binding Mode=OneWay, Path=Name}" />
                            </StackPanel>
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellTemplate>
                </dg:DataGridTemplateColumn>
                <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=QueueOrder, Converter={StaticResource QueuePriorityConvert}}" Header="Nr." IsReadOnly="True" />
                <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=SizeTotalBytes, Converter={StaticResource SizeShowZeroConverter}}" Header="Größe" IsReadOnly="True" />
                <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=SizeDownloadedBytes, Converter={StaticResource SizeShowZeroConverter}}" Header="Heruntergeladen" IsReadOnly="True" />
                <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=SizeRemainingBytes, Converter={StaticResource SizeConverter}}" Header="Restgröße" IsReadOnly="True" />
                <dg:DataGridTemplateColumn Header="Fertig %" SortMemberPath="ProgressPercent" IsReadOnly="True" >
                    <dg:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Grid>
                                <ProgressBar BorderThickness="1" BorderBrush="#FFF0F0F0" Maximum="1" Minimum="0" Value="{Binding Mode=OneWay, Path=ProgressPercent}" Background="White" Foreground="#FF5050FF" SmallChange="0.001">
                                </ProgressBar>
                                <TextBlock Text="{Binding Mode=OneWay, Path=ProgressPercent, StringFormat=0.0%}" TextAlignment="Center" />
                            </Grid>
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellTemplate>
                </dg:DataGridTemplateColumn>
                <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=SimpleStatus, Converter={StaticResource StatusConverter}}" Header="Status" IsReadOnly="True" />
                <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=Seeds}" SortMemberPath="SeedsTotal" Header="Seeds" IsReadOnly="True" />
                <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=Peers}" SortMemberPath="PeersTotal" Header="Peers" IsReadOnly="True" />
                <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=SeedsPeersRatio, Converter={StaticResource SeedPeerRatioConverter}}" Header="Seeds/Peers" IsReadOnly="True" />
                <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=SpeedDownloadBytes, Converter={StaticResource SpeedConverter}}" Header="DL-Rate" IsReadOnly="True" />
                <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=SpeedUploadBytes, Converter={StaticResource SpeedConverter}}" Header="UL-Rate" IsReadOnly="True" />
                <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=TimeEstimate, Converter={StaticResource TimeSpanConvert}}" Header="Restzeit" IsReadOnly="True" />
                <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=SizeUploadedBytes, Converter={StaticResource SizeShowZeroConverter}}" Header="Hochgeladen" IsReadOnly="True" />
                <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=SeedRatio, StringFormat=0.000}" Header="Ratio" IsReadOnly="True" />
                <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=Availability, StringFormat=0.000}" Header="Avail." IsReadOnly="True" />
                <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=Label}" Header="Label" IsReadOnly="True" />
            </dg:DataGrid.Columns>
        </dg:DataGrid>

        <TabControl Grid.Column="1" Grid.Row="2">
            <TabItem Header="Allgemein">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="120"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="120"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="30"/>
                        <RowDefinition Height="30"/>
                        <RowDefinition Height="30"/>
                        <RowDefinition Height="30"/>
                        <RowDefinition Height="30"/>
                        <RowDefinition Height="30"/>
                    </Grid.RowDefinitions>

                    <TextBlock Text="Restzeit:" Grid.Column="0" Grid.Row="0" FontWeight="Bold" />
                    <TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding  Mode=OneWay, Path=SelectedTorrent.TimeEstimate, Converter={StaticResource TimeSpanConvert}}"/>

                    <TextBlock Text="Share-Rate:" Grid.Column="0" Grid.Row="1" FontWeight="Bold" />
                    <TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding  Mode=OneWay, Path=SelectedTorrent.SeedRatio, StringFormat=0.000}"/>

                    <TextBlock Text="Seeds:" Grid.Column="0" Grid.Row="2" FontWeight="Bold" />
                    <TextBlock Grid.Column="1" Grid.Row="2" Text="{Binding  Mode=OneWay, Path=SelectedTorrent.Seeds}"/>

                    <TextBlock Text="Peers:" Grid.Column="0" Grid.Row="3" FontWeight="Bold" />
                    <TextBlock Grid.Column="1" Grid.Row="3" Text="{Binding  Mode=OneWay, Path=SelectedTorrent.Peers}"/>

                    <TextBlock Text="Prüf-ID:" Grid.Column="0" Grid.Row="4" FontWeight="Bold" />
                    <TextBlock Grid.Column="1" Grid.Row="4" Text="{Binding  Mode=OneWay, Path=SelectedTorrent.Hash}"/>

                    <TextBlock Text="Heruntergeladen:" Grid.Column="2" Grid.Row="0" FontWeight="Bold" />
                    <TextBlock Grid.Column="3" Grid.Row="0" Text="{Binding  Mode=OneWay, Path=SelectedTorrent.SizeDownloadedBytes, Converter={StaticResource SizeShowZeroConverter}}"/>

                    <TextBlock Text="Download-Rate:" Grid.Column="2" Grid.Row="1" FontWeight="Bold" />
                    <TextBlock Grid.Column="3" Grid.Row="1" Text="{Binding  Mode=OneWay, Path=SelectedTorrent.SpeedDownloadBytes, Converter={StaticResource SpeedConverter}}"/>

                    <TextBlock Text="Hochgeladen:" Grid.Column="2" Grid.Row="2" FontWeight="Bold" />
                    <TextBlock Grid.Column="3" Grid.Row="2" Text="{Binding Path=SelectedTorrent.SizeUploadedBytes, Converter={StaticResource SizeShowZeroConverter}}"/>

                    <TextBlock Text="Upload-Rate:" Grid.Column="2" Grid.Row="3" FontWeight="Bold" />
                    <TextBlock Grid.Column="3" Grid.Row="3" Text="{Binding  Mode=OneWay, Path=SelectedTorrent.SpeedUploadBytes, Converter={StaticResource SpeedConverter}}"/>

                    <TextBlock Text="DHT:" Grid.Column="2" Grid.Row="4" FontWeight="Bold" />
                    <TextBlock Grid.Column="3" Grid.Row="4" Text="{Binding  Mode=OneWay, Path=SelectedTorrent.DHT, Converter={StaticResource OptionValueConverter}}"/>

                    <TextBlock Text="PEX:" Grid.Column="2" Grid.Row="5" FontWeight="Bold" />
                    <TextBlock Grid.Column="3" Grid.Row="5" Text="{Binding  Mode=OneWay, Path=SelectedTorrent.PEX, Converter={StaticResource OptionValueConverter}}"/>

                </Grid>
            </TabItem>
            <TabItem Header="Dateien">
                <dg:DataGrid Grid.Row="1" Grid.Column="1" AutoGenerateColumns="False" ItemsSource="{Binding Mode=OneWay, Path=SelectedTorrent.Files}" BorderThickness="0" GridLinesVisibility="None" AlternatingRowBackground="Beige" SelectedItem="{Binding Path=SelectedFile, Mode=TwoWay}"
                     RowDetailsVisibilityMode="Collapsed" FontSize="11.5" HorizontalGridLinesBrush="Transparent" VerticalGridLinesBrush="Transparent" VerticalContentAlignment="Center">
                    <dg:DataGrid.ContextMenu>
                        <ContextMenu>
                            <MenuItem Header="Nicht Herunterladen" Command="{Binding Path=SetFileNoDownloadCommand}"/>
                            <MenuItem Header="Hoche Priorität" Command="{Binding Path=SetFileHighCommand}" />
                            <MenuItem Header="Normale Priorität" Command="{Binding Path=SetFileNormalCommand}" />
                            <MenuItem Header="Niedrige Priorität" Command="{Binding Path=SetFileLowCommand}" />
                        </ContextMenu>
                    </dg:DataGrid.ContextMenu>
                    <dg:DataGrid.Columns>
                        <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=Name}" Header="Datei" IsReadOnly="True" />
                        <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=TotalFileSize}" Header="Größe" IsReadOnly="True" />
                        <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=TotalFileSizeDownloaded}" Header="Heruntergeladen" IsReadOnly="True" />
                        <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=Priority, Converter={StaticResource FilePriorityConverter}}" Header="Prorität" IsReadOnly="True" />
                    </dg:DataGrid.Columns>
                </dg:DataGrid>
            </TabItem>
            <TabItem Header="Tracker">
                <dg:DataGrid Grid.Row="1" Grid.Column="1" AutoGenerateColumns="False" ItemsSource="{Binding Mode=OneWay, Path=SelectedTorrent.Trackers}" BorderThickness="0" GridLinesVisibility="None" AlternatingRowBackground="Beige"
                     RowDetailsVisibilityMode="Collapsed" FontSize="11.5" HorizontalGridLinesBrush="Transparent" VerticalGridLinesBrush="Transparent" VerticalContentAlignment="Center">
                    <dg:DataGrid.Columns>
                        <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=Address}" Header="Addresse" IsReadOnly="True" />
                    </dg:DataGrid.Columns>
                </dg:DataGrid>
            </TabItem>
            <TabItem Header="Protokoll">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="30"/>
                    </Grid.RowDefinitions>

                    <dg:DataGrid Grid.Row="0" AutoGenerateColumns="False" ItemsSource="{Binding Mode=OneWay, Path=Protokoll}" BorderThickness="0" GridLinesVisibility="None" AlternatingRowBackground="Beige"
                    RowDetailsVisibilityMode="Collapsed" FontSize="11.5" HorizontalGridLinesBrush="Transparent" VerticalGridLinesBrush="Transparent" VerticalContentAlignment="Center">
                        <dg:DataGrid.Columns>
                            <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=Date}" Header="Datum" IsReadOnly="True" SortDirection="Descending" />
                            <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=Type}" Header="Typ" IsReadOnly="True" />
                            <dg:DataGridTextColumn Binding="{Binding Mode=OneWay, Path=Message}" Header="Nachricht" IsReadOnly="True" />
                        </dg:DataGrid.Columns>
                    </dg:DataGrid>

                    <Button Grid.Row="1" Content="Protokoll leeren" Command="{Binding Path=ClearProtokollCommand}" HorizontalAlignment="Right" Margin="5"/>
                    
                </Grid>
                
            </TabItem>
        </TabControl>

        <Border Grid.Row="3" Grid.ColumnSpan="2" Margin="0" Background="#FFF1EDED">
            <StatusBar HorizontalAlignment="Right" >
                <StatusBarItem VerticalAlignment="Top">
                    <StackPanel Margin="0,0,5,0" Orientation="Horizontal">
                        <TextBlock Text="{Binding Path=TotalInfo}" />
                    </StackPanel>
                </StatusBarItem>
                <StatusBarItem VerticalAlignment="Top">
                    <StackPanel Margin="0,0,5,0" Orientation="Horizontal">
                        <TextBlock Text="Verbunden: "  VerticalAlignment="Top" FontWeight="Bold" />
                        <TextBlock Text="{Binding Path=Connected, Converter={StaticResource BoolConverter}}" Name="Connect" Style="{StaticResource ConnectedStyle}" FontWeight="Bold" />
                    </StackPanel>
                </StatusBarItem>
                <StatusBarItem VerticalAlignment="Top">
                    <StackPanel Margin="0,0,5,0" Orientation="Horizontal">
                        <TextBlock Text="Server: "  VerticalAlignment="Top" FontWeight="Bold" />
                        <TextBlock Text="{Binding Path=AppSetting.Server}"/>
                    </StackPanel>
                </StatusBarItem>
                <StatusBarItem  VerticalAlignment="Top">
                    <StackPanel Margin="0,0,5,0" Orientation="Horizontal">
                        <TextBlock Text="Port: " FontWeight="Bold" />
                        <TextBlock Text="{Binding Path=AppSetting.Port}"/>
                    </StackPanel>
                </StatusBarItem>
                <StatusBarItem  VerticalAlignment="Top">
                    <StackPanel Margin="0,0,5,0" Orientation="Horizontal">
                        <TextBlock Text="Aktualisierungszeit: " FontWeight="Bold" />
                        <TextBlock Text="{Binding Path=AppSetting.RefreshSec}"/>
                        <TextBlock Text=" sec"/>
                    </StackPanel>
                </StatusBarItem>
            </StatusBar>
        </Border>

        <!--settings:SettingsView/-->

    </Grid>
</UserControl>
